import { sha256 } from 'js-sha256';

export const hashStr = (value: string) => {
  return sha256(value);
};

export const checkPasswordStrength = (password: string) => {
  // 定义四种字符类型正则
  const hasUpper = /[A-Z]/.test(password);
  const hasLower = /[a-z]/.test(password);
  const hasDigit = /[0-9]/.test(password);
  const hasSpecial = /[!@#$%^&*()_+\-=$$$${};':"\\|,.<>/?]/.test(password);

  // 计算符合的条件数量
  const conditionsMet = [hasUpper, hasLower, hasDigit, hasSpecial].filter(Boolean).length;

  // 长度要求 + 至少3种类型
  return password.length >= 8 && conditionsMet >= 3;
};
